package com.wzxy.nc.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.wzxy.nc.dao.IBaseDao;
import com.wzxy.nc.service.IBaseService;

@Service
@Lazy(true)
public class BaseService<T> implements IBaseService<T>{
	
	@Autowired
	private IBaseDao<T> baseDao;
	
	protected void beforeInsert(T t){};
	
	protected void afterInsert(T t){};
	
	protected void beforeUpdate(T t){};
	
	protected void afterUpdate(T t){};

	@Override
	public T insert(T t) {
		beforeInsert(t);
		T o = baseDao.insert(t);
		afterInsert(t);
		return o;
	}

	@Override
	public T update(T t) {
		beforeUpdate(t);
		T o = baseDao.update(t);
		afterUpdate(t);
		return o;
	}

	@Override
	public void delete(Serializable id) {
		baseDao.delete(id);
	}

	@Override
	public T findById(Serializable id) {
		return baseDao.findById(id);
	}

	@Override
	public List<T> findAll() {
		return baseDao.findAll();
	}

	@Override
	public  void setBaseDao(IBaseDao<T> baseDao) {
		this.baseDao = baseDao;
	}

}
